import request from '@/utils/requets'

enum API {
    SPU_BASEURL = '/admin/product/',
    // 品牌
    SPU_PP = '/admin/product/baseTrademark/getTrademarkList',
    SPU_IMAFES = '/admin/product/spuImageList/',
    // 已有属性
    SPU_ATTR = 'admin/product/spuSaleAttrList/',
    // 所有属性
    SPU_ALLATTR = 'admin/product/baseSaleAttrList',
    //追加一个新的SPU
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    //更新已有的SPU
    UPDATESPU_URL = '/admin/product/updateSpuInfo',
    //追加一个新增的SKU地址
    ADDSKU_URL = '/admin/product/saveSkuInfo',
    //查看某一个已有的SPU下全部售卖的商品
    SKUINFO_URL = '/admin/product/findBySpuId/',
    //删除已有的SPU
    REMOVESPU_URL = '/admin/product/deleteSpu/',
}
import type {
    ReturnSUP,
    SorN,
    SpuValue,
    ReturnPpList,
    ReturnImages,
    ReturnAttr,
    ReturnAllAttr,
    SkuAdd,
} from './type'
// 获取SPU数据
export const productSpu = (
    pageNo: number,
    pageSize: number,
    category3Id: SorN,
) =>
    request.get<any, ReturnSUP>(
        `${API.SPU_BASEURL}${
            pageNo + '/' + pageSize
        }?category3Id=${category3Id}`,
    )
// 获取品牌
export const getTrademarkList = () => request.get<any, ReturnPpList>(API.SPU_PP)
// 获取照片墙
export const getSpuImageList = (spuId: SorN) =>
    request.get<any, ReturnImages>(API.SPU_IMAFES + spuId)

// 获取已有spu属性
export const getSpuSaleAttrList = (spuId: SorN) =>
    request.get<any, ReturnAttr>(API.SPU_ATTR + spuId)

// 获取所有属性
export const getBaseSaleAttrList = () =>
    request.get<any, ReturnAllAttr>(API.SPU_ALLATTR)
//添加一个新的SPU的
//更新已有的SPU接口
//data:即为新增的SPU|或者已有的SPU对象
export const addOrUpdataSpu = (data: SpuValue) => {
    let url = ''
    data.id ? (url = API.UPDATESPU_URL) : (url = API.ADDSPU_URL)
    return request.post<any, any>(url, data)
}

//添加SKU的请求方法
export const reqAddSku = (data: SkuAdd) =>
    request.post<any, any>(API.ADDSKU_URL, data)

//获取SKU数据
export const reqSkuList = (spuId: number | string) =>
    request.get<any, any>(API.SKUINFO_URL + spuId)

//删除已有的SPU
export const reqRemoveSpu = (spuId: number | string) =>
    request.delete<any, any>(API.REMOVESPU_URL + spuId)
